/**
 * author      : dormi330
 * date        : 2018/6/24
 * project     : mybatis
 * description : 交易订单实体
 * <p>
 * 一个订单包含多条 item, 但是一次支付
 * 物流可以包含多个
 */

package com.deep.trade.infrastructure.mybatis.cart;

import com.deep.trade.application.AppRuntimeEvn;
import com.deep.trade.domain.cart.CartQueryRepository;
import com.deep.trade.domain.cart.CartSku;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class MybatisCartQueryRepository implements CartQueryRepository {

    @Autowired
    private AppRuntimeEvn appRuntimeEvn;

    @Autowired
    private CartSkuMapper cartSkuMapper;

    // 查询单个 cart
    public CartSku cartOfSpecificMemberAndSku(String memberId, String skuId) {
        String tenantCode = appRuntimeEvn.getTenantCode();
        return cartSkuMapper.findOneByMeberAndSku(tenantCode, memberId, skuId);
    }

    public PageInfo<CartSku> cartListOfMember(String memberId, int pageNum, int pageSize) throws Exception {
        String tenantCode = appRuntimeEvn.getTenantCode();

        PageHelper.startPage(pageNum, pageSize);
        // Mybatis查询方法
        List<CartSku> cartSkuList = cartSkuMapper.listByMember(tenantCode, memberId);
        // 用PageInfo对结果进行包装
        return new PageInfo<>(cartSkuList);
    }
}
